<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav main-header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            容器先进先出查询
    </header>
    <div class="aui-bar aui-bar-nav sub-header"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;padding-bottom: 50px;">
        <div class="white_background">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">条码</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请扫描条码" id="trayyinfoid" value="" onclick="getIdSelector();">
                        </div>
                    </div>
                </li>
            </ul>
            <div style="width:100%;margin-top:2%;"></div>
            <div class="aui-btn aui-btn-info aui-btn-block" onclick="getTrayInfo()">查询</div>
            <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:2%;"
                id="tbodyHtml">
            </div>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var html = ""; //全局拼接HTML
    var arrSave = [];
    var array = new Array();
    //初始化查询仓库下拉框
    apiready = function () {

        $("#trayyinfoid").focus();
        idSelector = "trayyinfoid";
        //查询条码解析规则
        initScanRule();

    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            if (idSelector == 'trayyinfoid') {
                //容器条码
                $("#trayyinfoid").val(ret);
                getTrayInfo();
            }
        });
    }

    //条码监听回车事件
    $("#trayyinfoid").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                console.log(tm);
                $("#trayyinfoid").val(tm);
                getTrayInfo();
            }

        }
    });

    function getTrayInfo() {
        if (!clickThrottle()) {
            return;
        }


        var sm = $("#trayyinfoid").val();

        if (sm == '' || sm == null || sm == undefined) {
            api.toast({
                msg: "请输入容器条码！",
                duration: 3000
            });
            return
        }
        if (sm.split(',').length > 1) {
            api.toast({
                msg: "请输入容器条码！",
                duration: 3000
            });
            return
        }
        api.showProgress({
            title: '查询中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchContainerInOut";
        var data = {
            values: {
                sm: sm,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                var html = ""
                if (myobj.code == "0") {
                    api.hideProgress();
                    html += "<div id = '' class='aui-btn-info aui-btn-block' style='border-radius: 10px;margin-bottom: 10px;color: black !important;background-color: #D0D0D0 !important;height: 120px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                    html += "<table style='width:100%;height:100%'>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>仓库：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCenterCode + ":" + myobj.workCenterName + "</td></tr>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>库位：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCellCode + ":" + myobj.workCellName + "</td></tr>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>提示：</td> <td  id='cellCodetital' style='width:70%;'>" + "当前容器内对应物料符合先进先出规则，可以出库！" + "</td></tr>";
                    html += "</table></div>";
                    $api.html($api.byId("tbodyHtml"), html);
                    $("#trayyinfoid").val("");
                    $("#trayyinfoid").select();
                    idSelector = "trayyinfoid";
                } else if (myobj.code == "1") {
                    api.hideProgress();
                    html += "<div id = '' class='aui-btn-info aui-btn-block' style='border-radius: 10px;margin-bottom: 10px;color: black !important;background-color: red !important;height: 120px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                    html += "<table style='width:100%;height:100%'>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>仓库：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCenterCode + ":" + myobj.workCenterName + "</td></tr>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>库位：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCellCode + ":" + myobj.workCellName + "</td></tr>";
                    html += "<tr style='width:100%;'><td style='width:30%;'>错误提示：</td> <td  id='cellCodetital' style='width:70%;'>" + "当前容器内对应物料不符合先进先出规则，无法出库！" + "</td></tr>";
                    html += "</table></div>";
                    var list = myobj.lotCodeList
                    if (list != null && list.length > 0) {
                        for (var i = 0; i < list.length; i++) {
                            html += "<div id = '' class='aui-btn-info aui-btn-block' style='border-radius: 10px;margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 120px;padding: 0.2rem 0.2rem;font-size: 0.7rem;display:flex;align-items:center'>";
                            html += "<table style='width:100%;height:100%'>";
                            html += "<tr style='width:100%;'><td style='width:30%;'>物料：</td> <td  id='cellCodetital' style='width:70%;'>" + list[i].mrlCode + "</td></tr>";
                            if (list[i].minName == "仓库") {
                                html += "<tr style='width:100%;'><td style='width:30%;'>仓库：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCenterCode + ":" + myobj.workCenterName + "</td></tr>";
                            } else if (list[i].minName == "库位") {
                                html += "<tr style='width:100%;'><td style='width:30%;'>库位：</td> <td  id='cellCodetital' style='width:70%;'>" + myobj.workCellCode + ":" + myobj.workCellName + "</td></tr>";
                            }


                            html += "<tr style='width:100%;'><td style='width:30%;'>最小批次：</td> <td  id='cellCodetital' style='width:70%;'>" + list[i].lotCode + "</td></tr>";
                            html += "</table></div>";
                        }
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    $("#trayyinfoid").val("");
                    $("#trayyinfoid").select();
                    idSelector = "trayyinfoid";

                }
            } else {
                api.hideProgress();

                $("#trayyinfoid").val("");
                $("#trayyinfoid").select();
                idSelector = "trayyinfoid";
                alert("连接超时，请耐心等待");
            }
        });
    }



    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>